package top.api.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;

public enum CommonSexEnum {
    //用户性别（0男，1女，2未知）
    MALE(0, "男"),
    FEMALE(1, "女"),
    unknown(2,"未知");

    CommonSexEnum(int code, String sex) {
        this.code = code;
        this.sex = sex;
    }
    /**
     * 标记数据库存的值是code
     */
    @EnumValue
    private final int code;
    /**
     * 标记前端展示、已经更新传的值
     */
    @JsonValue
    private final String sex;

    public int getCode() {
        return code;
    }

    public String getSex() {
        return sex;
    }

    public static CommonSexEnum getCommonSexEnumByCode(int code) {
        for (CommonSexEnum commonSexEnum : CommonSexEnum.values()) {
            if (commonSexEnum.getCode() == code) {
                return commonSexEnum;
            }
        }
        throw new RuntimeException("没有满足条件的枚举");
    }
}
